<section class="header clearfix">
  <div class="pull-left">
    <h1>{{t "accountsPage.detail.header"}}</h1>
  </div>
  <div class="right-buttons">
    {{#link-to "security.accounts.edit" model.user.id classNames="btn bg-primary"}}{{t "generic.edit"}}{{/link-to}}
  </div>
</section>

{{#if model.user.description}}
  <div class="row mb-30">
    {{banner-message color="bg-secondary mb-0 mt-10" message=(linkify model.user.description)}}
  </div>
{{/if}}

<section>
  <div class="row banner bg-info basics">
    <div class="vertical-middle">
      <label class="acc-label vertical-middle p-0">{{t "accountsPage.new.form.username.labelText"}}</label>
      {{model.user.username}} {{copy-to-clipboard clipboardText=model.user.username size="small"}}
    </div>
    <div class="vertical-middle">
      <label class="acc-label vertical-middle p-0">{{t "accountsPage.new.form.name.labelText"}}</label>
      {{#if model.user.name.length}}
        {{model.user.name}} {{copy-to-clipboard clipboardText=model.user.name size="small"}}
      {{else}}
        {{t "generic.na"}}
      {{/if}}
    </div>
  </div>
</section>

<hr class="mt-30 mb-30" />

<section>
  {{#accordion-list-item
     title=(t "accountsPage.detail.table.global.title")
     detail=(t "accountsPage.detail.table.global.description")
     expandOnInit=true
     showExpand=false
  }}
    {{#if model.user.hasAdmin}}
      <div class="text-center mt-20 mb-20 text-bold text-success">
        {{t "accountsPage.detail.table.global.admin"}}
      </div>
    {{else}}
      {{#sortable-table
         classNames="grid sortable-table"
         body=globalRoleMapping
         search=false
         sortBy=sortGlobalBy
         descending=globalDescending
         bulkActions=false
         pagingLabel="pagination.role"
         headers=globalHeaders as |sortable kind entry dt|
      }}
        {{#if (eq kind "row")}}
          <tr class="main-row {{if entry.enabled "" "text-muted"}}">
            <td data-title="{{dt.enabled}}">
              {{#if entry.enabled}}
                <i class="icon icon-check"/>
              {{else}}
                <i class="icon icon-x"/>
              {{/if}}
            </td>
            <td data-title="{{dt.name}}">
              {{entry.role.displayName}}
            </td>
            <td data-title="{{dt.created}}">
              {{#if entry.enabled}}
                {{date-from-now entry.binding.created}}
              {{else}}
                {{t "generic.na"}}
              {{/if}}
            </td>
            <td data-title="{{dt.actions}}" class="actions">
              {{#if entry.enabled}}
                {{action-menu model=entry.binding}}
              {{/if}}
            </td>
          </tr>
        {{else if (eq kind "norows")}}
          <tr>
            <td colspan="{{sortable.fullColspan}}" class="text-center text-muted pt-20 pb-20">
              {{t "accountsPage.detail.table.global.noRoles"}}
            </td>
          </tr>
        {{/if}}
      {{/sortable-table}}
    {{/if}}
  {{/accordion-list-item}}
</section>

<section class="mt-20">
  {{#accordion-list-item
     title=(t "accountsPage.detail.table.cluster.title")
     detail=(t "accountsPage.detail.table.cluster.description")
     expandOnInit=true
     showExpand=false
  }}
    {{#sortable-table
       classNames="grid sortable-table"
       body=model.user.clusterRoleBindings
       search=false
       sortBy=sortClusterBy
       descending=descending
       bulkActions=false
       pagingLabel="pagination.role"
       headers=clusterHeaders as |sortable kind binding dt|
    }}
      {{#if (eq kind "row")}}
        <tr class="main-row">
          <td data-title="{{dt.cluster}}">
            <a href="#" {{action "launchOnCluster" binding.project }}>
              {{binding.cluster.displayName}}
            </a>
          </td>
          <td data-title="{{dt.name}}">
            {{binding.roleTemplate.displayName}}
          </td>
          <td data-title="{{dt.created}}">
            {{date-from-now binding.created}}
          </td>
          <td data-title="{{dt.actions}}" class="actions">
            {{action-menu model=binding}}
          </td>
        </tr>
      {{else if (eq kind "norows")}}
        <tr>
          <td colspan="{{sortable.fullColspan}}" class="text-center text-muted pt-20 pb-20">
            {{t "accountsPage.detail.table.cluster.noRoles"}}
          </td>
        </tr>
      {{/if}}
    {{/sortable-table}}
  {{/accordion-list-item}}
</section>

<section class="mt-20">
  {{#accordion-list-item
     title=(t "accountsPage.detail.table.project.title")
     detail=(t "accountsPage.detail.table.project.description")
     expandOnInit=true
     showExpand=false
  }}
    {{#sortable-table
       classNames="grid sortable-table"
       body=model.user.projectRoleBindings
       search=false
       sortBy=sortProjectBy
       descending=projectDescending
       bulkActions=false
       pagingLabel="pagination.role"
       headers=projectHeaders as |sortable kind binding dt|
    }}
      {{#if (eq kind "row")}}
        <tr class="main-row">
          <td data-title="{{dt.project}}">
            {{#link-to-external "authenticated.cluster.projects" role.project.id}}
              {{binding.project.displayName}}
            {{/link-to-external}}
          </td>
          <td data-title="{{dt.name}}">
            {{binding.roleTemplate.displayName}}
          </td>
          <td data-title="{{dt.created}}">
            {{date-from-now binding.created}}
          </td>
          <td data-title="{{dt.actions}}" class="actions">
            {{action-menu model=binding}}
          </td>
        </tr>
      {{else if (eq kind "norows")}}
        <tr>
          <td colspan="{{sortable.fullColspan}}" class="text-center text-muted pt-20 pb-20">
            {{t "accountsPage.detail.table.project.noRoles"}}
          </td>
        </tr>
      {{/if}}
    {{/sortable-table}}
  {{/accordion-list-item}}
</section>
